package com.zmsoft.boxy.sfg.service;

import org.cnsoft.framework.beans.common.RESTResultBean;
import org.cnsoft.framework.utils.EmptyHelper;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Service;

import com.zmsoft.boxy.sfg.player.BoxySFGPlayer;
import com.zmsoft.boxy.sfg.player.SfgPlayerFriendDBO;
import com.zmsoft.persistent.sfg.Sfg661010PlayerFarm.Sfg661010PlayerFarmDBO;

/**
 * 游戏玩家间交互
 * 
 * @author ZmSoft
 * @version 0.1.0 2018/3/1
 * @since 0.1.0 2018/3/1
 * @see ApiManagerLoginController
 */
@Service("SFGGameInteractService") // 替换系统登录接口
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SFGGameInteractService extends MySFGGameServiceSupport {

	/**
	 * 浇水
	 */
	public RESTResultBean<BoxySFGPlayer> doCropsWatering(BoxySFGPlayer toPlayer) throws Exception {
		// TODO Auto-generated method stub
		return new RESTResultBean<BoxySFGPlayer>();
	}

	/**
	 * 除草
	 */
	public RESTResultBean<BoxySFGPlayer> doCropsWeed(BoxySFGPlayer toPlayer) throws Exception {
		// TODO Auto-generated method stub
		return new RESTResultBean<BoxySFGPlayer>();
	}

	/**
	 * 杀虫
	 */
	public RESTResultBean<BoxySFGPlayer> doCropsInsecticidal(BoxySFGPlayer toPlayer) throws Exception {
		// TODO Auto-generated method stub
		return new RESTResultBean<BoxySFGPlayer>();
	}

	/**
	 * 偷取果实
	 */
	public RESTResultBean<BoxySFGPlayer> doStealFruit(BoxySFGPlayer toPlayer) throws Exception {
		// TODO Auto-generated method stub
		return new RESTResultBean<BoxySFGPlayer>();
	}

	/**
	 * 添加好友
	 * @throws Exception 
	 */
	public RESTResultBean<BoxySFGPlayer> doPlayerFriend(BoxySFGPlayer toPlayer) throws Exception {
		RESTResultBean<BoxySFGPlayer> result = new RESTResultBean<BoxySFGPlayer>();
		
		//简单处理，便于维护
		BoxySFGPlayer player = new BoxySFGPlayer();
		player.setId(toPlayer.getPlayerFriendId());
		Sfg661010PlayerFarmDBO playerFarm = sfgPlayerInfoCacheService.loadPlayerFarm(player);
		
		//添加好友
		if(EmptyHelper.isNotEmpty(playerFarm)) {
			SfgPlayerFriendDBO friend = new SfgPlayerFriendDBO();
			friend.setPlayerFriendId(playerFarm.getPlayerId());
			friend.setPlayerFriendName(playerFarm.getPlayerName());
			sfgPlayerInfoCacheService.savePlayerFriend(toPlayer.init(), friend);
			result.setMsg(ACTION_MESSAGE_Friend);
		}else {
			result.setCode(1);
			result.setMsg(ACTION_FAIL_MESSAGE);
		}
		return result;
	}

}
